﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>课程管理</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
            background: #f5f7fa;
            margin: 0;
            padding: 0;
        }
        .header {
            background: #2196f3;
            color: #fff;
            padding: 0 32px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 56px;
            box-shadow: 0 2px 8px rgba(33,150,243,0.08);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }
        .header-left {
            display: flex;
            align-items: center;
        }
        .header-logo {
            width: 36px;
            height: 36px;
            margin-right: 12px;
        }
        .header-title {
            font-size: 1.4rem;
            font-weight: bold;
            letter-spacing: 1px;
        }
        .header-nav {
            margin-left: 32px;
            font-size: 1rem;
        }
        .header-nav a {
            color: #fff;
            text-decoration: none;
            margin-right: 16px;
            opacity: 0.85;
        }
        .header-nav a.active, .header-nav a:hover {
            opacity: 1;
            font-weight: bold;
        }

        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            bottom: 0;
            width: 220px;
            background: #fff;
            box-shadow: 2px 0 8px rgba(33,150,243,0.06);
            overflow-y: auto;
            z-index: 100;
            padding-top: 16px;
        }
        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .sidebar-menu > li {
            margin-bottom: 4px;
        }
        .sidebar-menu > li > a {
            display: flex;
            align-items: center;
            padding: 10px 24px;
            color: #333;
            text-decoration: none;
            border-radius: 8px 0 0 8px;
            transition: background 0.2s, color 0.2s;
            font-size: 1rem;
        }
        .sidebar-menu > li > a:hover, .sidebar-menu > li > a.active {
            background: #e3f2fd;
            color: #2196f3;
            font-weight: bold;
        }
        .sidebar-menu > li > a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
        }
        .sidebar-submenu {
            list-style: none;
            padding-left: 40px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }
        .sidebar-menu > li.open .sidebar-submenu {
            max-height: 500px;
        }
        .sidebar-submenu > li > a {
            display: block;
            padding: 7px 0;
            color: #666;
            text-decoration: none;
            transition: color 0.2s;
            font-size: 0.98rem;
        }
        .sidebar-submenu > li > a:hover, .sidebar-submenu > li > a.active {
            color: #2196f3;
            font-weight: 500;
        }
        .content {
            margin-left: 240px;
            padding: 80px 32px 32px;
        }
        .card {
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 2px 12px rgba(33,150,243,0.07);
            margin-bottom: 24px;
            border: none;
        }
        .card-body {
            padding: 24px 24px 16px 24px;
        }
        .search-bar {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 18px;
        }
        .search-bar input {
            border-radius: 8px;
            border: 1px solid #e3e3e3;
            padding: 6px 14px;
            font-size: 1rem;
            width: 220px;
        }
        .search-bar .btn {
            border-radius: 8px;
            font-size: 1rem;
            padding: 6px 18px;
            font-weight: 500;
            box-shadow: none;
        }
        .btn-primary {
            background: #2196f3;
            border: none;
        }
        .btn-primary:hover {
            background: #1976d2;
        }
        .table {
            background: #fff;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(33,150,243,0.04);
        }
        .table thead th {
            background: #f5f7fa;
            color: #2196f3;
            font-weight: bold;
            text-align: center;
            border-bottom: 2px solid #e3e3e3;
        }
        .table tbody tr {
            transition: background 0.2s;
        }
        .table tbody tr:hover {
            background: #f1f8ff;
        }
        .table td, .table th {
            vertical-align: middle !important;
            text-align: center;
        }
        .pagination {
            justify-content: center;
            margin-top: 12px;
        }
        .pagination .page-item .page-link {
            border-radius: 6px !important;
            margin: 0 2px;
            color: #2196f3;
            border: none;
            background: #fff;
            font-weight: 500;
            transition: background 0.2s, color 0.2s;
        }
        .pagination .page-item.active .page-link {
            background: #2196f3;
            color: #fff;
        }
        .pagination .page-item .page-link:hover {
            background: #e3f2fd;
            color: #1976d2;
        }

        .course-type {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.8rem;
            font-weight: 500;
        }
        .course-type.required {
            background-color: #ffebee;
            color: #d32f2f;
        }
        .course-type.elective {
            background-color: #e8f5e8;
            color: #2e7d32;
        }

        .btn-action {
            padding: 6px 12px;
            margin: 0 2px;
            border-radius: 6px;
            font-size: 0.85rem;
            font-weight: 500;
            transition: all 0.2s ease;
            border: none;
        }
        .btn-select {
            background-color: #4caf50;
            color: white;
        }
        .btn-select:hover {
            background-color: #45a049;
        }
        .btn-disabled {
            background-color: #9e9e9e;
            color: white;
            cursor: not-allowed;
        }

        .schedule-info {
            font-size: 0.9rem;
            color: #666;
            margin: 2px 0;
        }
        .weekday-mapping {
            display: inline-block;
            padding: 2px 6px;
            background-color: #e3f2fd;
            border-radius: 4px;
            font-size: 0.8rem;
            margin: 1px 2px;
            color: #2196f3;
        }

        /* 用户名下拉菜单 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown::before {
            content: '';
            position: absolute;
            top: -6px;
            right: 20px;
            width: 12px;
            height: 12px;
            background: #fff;
            transform: rotate(45deg);
            box-shadow: -2px -2px 4px rgba(0,0,0,0.1);
        }
        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background: #f8f9fa;
            color: #2196f3;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        @media (max-width: 900px) {
            .content {
                margin-left: 0;
                padding: 80px 10px 10px;
            }
            .sidebar {
                width: 100%;
                position: static;
                box-shadow: none;
            }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <div class="header-left">
        <img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo" class="header-logo">
        <span class="header-title">教务管理系统</span>
        <div class="header-nav">
            <a href="${pageContext.request.contextPath}/student/home">首页</a>
            <span style="opacity:0.5;">/</span>
            <a href="#" class="active">课程管理</a>
        </div>
    </div>

    <!-- 用户名下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户名头像" id="userAvatar">
        <span class="header-user-name" id="userName">
            <c:choose>
                <c:when test="${not empty currentStudent and not empty currentStudent.user and not empty currentStudent.user.realName}">
                    ${currentStudent.user.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                    ${sessionScope.loggedInUser.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                    ${sessionScope.loggedInUser.username}
                </c:when>
                <c:otherwise>
                    学生
                </c:otherwise>
            </c:choose>
        </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                个人资料
            </a>
            <a href="${pageContext.request.contextPath}/student/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                登出
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<div class="sidebar">
    <ul class="sidebar-menu">
        <li>
            <a href="${pageContext.request.contextPath}/student/home" class="active">
                <i class="bi bi-house-door"></i> 学生首页
            </a>
        </li>
        <li>
            <a href="#" class="has-submenu" onclick="toggleSubmenu(this)">
                <i class="bi bi-megaphone"></i> 通知公告
                <i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/student/notifications/academic">教务通知</a></li>
                <li><a href="${pageContext.request.contextPath}/student/notifications/exam">考试安排</a></li>
                <li><a href="${pageContext.request.contextPath}/student/notifications/classroom">教室安排</a></li>
            </ul>
        </li>
        <li>
            <a href="#" class="has-submenu" onclick="toggleSubmenu(this)">
                <i class="bi bi-building"></i> 院系管理
                <i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/student/college">学院管理</a></li>
                <li><a href="${pageContext.request.contextPath}/student/major">专业管理</a></li>
                <li><a href="${pageContext.request.contextPath}/student/class">班级管理</a></li>
            </ul>
        </li>
        <li>
            <a href="#" class="has-submenu" onclick="toggleSubmenu(this)">
                <i class="bi bi-book"></i> 课程管理
                <i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/student/courses">课程管理</a></li>
                <li><a href="${pageContext.request.contextPath}/student/my-courses">我的课程</a></li>
                <li><a href="${pageContext.request.contextPath}/student/schedule">我的课表</a></li>
                <li><a href="${pageContext.request.contextPath}/student/grades">成绩管理</a></li>
                <li><a href="${pageContext.request.contextPath}/student/evaluation">课程评价</a></li>
            </ul>
        </li>
        <li>
            <a href="#" class="has-submenu" onclick="toggleSubmenu(this)">
                <i class="bi bi-clipboard-check"></i> 教学管理
                <i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/student/leave">请假管理</a></li>
                <li><a href="${pageContext.request.contextPath}/student/homework">作业提交</a></li>
                <li><a href="${pageContext.request.contextPath}/student/attendance">考勤管理</a></li>
            </ul>
        </li>
    </ul>
</div>

<!-- 内容区域 -->
<div class="content">
    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
            <i class="bi bi-exclamation-triangle"></i> ${error}
        </div>
    </c:if>

    <!-- 课程搜索 -->
    <div class="card">
        <div class="card-body">
            <h5 class="mb-3"><i class="bi bi-search me-2"></i>搜索课程</h5>
            <form method="get" action="/ssm/student/courses" class="search-bar">
                <input type="text" class="form-control" name="nameSearch"
                       value="${nameSearch}" placeholder="请输入课程名称或关键字">
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-search me-1"></i>搜索
                </button>
                <button type="button" class="btn btn-outline-secondary" onclick="resetSearch()">
                    <i class="bi bi-arrow-clockwise me-1"></i>重置
                </button>
            </form>
        </div>
    </div>

    <!-- 课程列表 -->
    <div class="card">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="mb-0"><i class="bi bi-journal-bookmark me-2"></i>课程列表</h5>
                <small class="text-muted">共 ${totalRecords} 条记录</small>
            </div>

            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>课程名称</th>
                        <th>课程类型</th>
                        <th>授课教师</th>
                        <th>学分</th>
                        <th>选课人数</th>
                        <th>授课教室</th>
                        <th>授课时间</th>
                        <th>授课节次</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:if test="${empty courses}">
                        <tr>
                            <td colspan="10" class="text-center py-4 text-muted">
                                <i class="bi bi-inbox" style="font-size: 2rem;"></i><br>
                                没有找到课程数据
                            </td>
                        </tr>
                    </c:if>
                    <c:forEach var="course" items="${courses}" varStatus="status">
                        <tr>
                            <td>${(currentPage - 1) * pageSize + status.index + 1}</td>
                            <td class="fw-bold text-primary">${course.name}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${course.status eq 1}">
                                        <span class="course-type elective">选修</span>
                                    </c:when>
                                    <c:otherwise>
                                        <span class="course-type required">必修</span>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            <td>
                                <c:choose>
                                    <c:when test="${not empty course.teacher and not empty course.teacher.user}">
                                        ${course.teacher.user.realName}
                                    </c:when>
                                    <c:otherwise>未分配教师</c:otherwise>
                                </c:choose>
                            </td>
                            <td>${course.credits}</td>
                            <td>
                                <c:set var="selectedCount" value="0"/>
                                <c:forEach var="courseSelectionTemp" items="${studentCourseSelections}">
                                    <c:if test="${courseSelectionTemp.course.id eq course.id and courseSelectionTemp.status eq 1}">
                                        <c:set var="selectedCount" value="${selectedCount + 1}"/>
                                    </c:if>
                                </c:forEach>
                                    ${selectedCount}/${course.maxStudents}
                            </td>
                            <td>
                                <c:if test="${not empty course.courseScheduleList}">
                                    <c:forEach var="schedule" items="${course.courseScheduleList}" varStatus="scheduleStatus">
                                        <div class="schedule-info">${schedule.classroom}</div>
                                    </c:forEach>
                                </c:if>
                                <c:if test="${empty course.courseScheduleList}">
                                    <span class="text-muted">未安排</span>
                                </c:if>
                            </td>
                            <td>
                                <c:if test="${not empty course.courseScheduleList}">
                                    <c:forEach var="schedule" items="${course.courseScheduleList}">
                                        <c:choose>
                                            <c:when test="${schedule.weekday eq 1}">
                                                <span class="weekday-mapping">周一</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 2}">
                                                <span class="weekday-mapping">周二</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 3}">
                                                <span class="weekday-mapping">周三</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 4}">
                                                <span class="weekday-mapping">周四</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 5}">
                                                <span class="weekday-mapping">周五</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 6}">
                                                <span class="weekday-mapping">周六</span>
                                            </c:when>
                                            <c:when test="${schedule.weekday eq 7}">
                                                <span class="weekday-mapping">周日</span>
                                            </c:when>
                                        </c:choose>
                                    </c:forEach>
                                </c:if>
                            </td>
                            <td>
                                <c:if test="${not empty course.courseScheduleList}">
                                    <c:forEach var="schedule" items="${course.courseScheduleList}">
                                        <c:choose>
                                            <c:when test="${schedule.period eq 1}">
                                                <span class="weekday-mapping">第一节课 (08:00 - 09:30)</span>
                                            </c:when>
                                            <c:when test="${schedule.period eq 2}">
                                                <span class="weekday-mapping">第二节课 (09:40 - 12:00)</span>
                                            </c:when>
                                            <c:when test="${schedule.period eq 3}">
                                                <span class="weekday-mapping">第三节课 (14:00 - 15:30)</span>
                                            </c:when>
                                            <c:when test="${schedule.period eq 4}">
                                                <span class="weekday-mapping">第四节课 (15:40 - 17:00)</span>
                                            </c:when>
                                        </c:choose>
                                    </c:forEach>
                                </c:if>
                            </td>
                            <td>
                                <!-- 判断是否已经选课 -->
                                <c:set var="isSelected" value="false"/>
                                <c:set var="selectionStatus" value="0"/>
                                <c:forEach var="selection" items="${studentCourseSelections}">
                                    <c:if test="${selection.course.id eq course.id}">
                                        <c:set var="isSelected" value="true"/>
                                        <c:set var="selectionStatus" value="${selection.status}"/>
                                    </c:if>
                                </c:forEach>

                                <c:choose>
                                    <c:when test="${isSelected and selectionStatus eq 1}">
                                        <button type="button" class="btn btn-action btn-disabled" disabled>
                                            <i class="bi bi-check-circle me-1"></i>已选
                                        </button>
                                    </c:when>
                                    <c:when test="${isSelected and selectionStatus eq 0}">
                                        <button type="button" class="btn btn-action btn-disabled" disabled>
                                            <i class="bi bi-clock me-1"></i>审核中
                                        </button>
                                    </c:when>
                                    <c:when test="${isSelected and selectionStatus eq 2}">
                                        <button type="button" class="btn btn-action btn-select"
                                                onclick="selectCourse(${course.id})">
                                            <i class="bi bi-arrow-clockwise me-1"></i>重新选课
                                        </button>
                                    </c:when>
                                    <c:otherwise>
                                        <button type="button" class="btn btn-action btn-select"
                                                onclick="selectCourse(${course.id})">
                                            <i class="bi bi-plus-circle me-1"></i>选课
                                        </button>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            <c:if test="${totalPages gt 1}">
                <nav aria-label="Page navigation" class="mt-3">
                    <ul class="pagination">
                        <c:if test="${currentPage gt 1}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage - 1}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        </c:if>

                        <c:forEach begin="1" end="${totalPages > 5 ? 5 : totalPages}" var="i">
                            <li class="page-item <c:if test='${i eq currentPage}'>active</c:if>">
                                <a class="page-link" href="?page=${i}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>">${i}</a>
                            </li>
                        </c:forEach>

                        <c:if test="${currentPage lt totalPages}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage + 1}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </c:if>
                    </ul>
                </nav>
            </c:if>
        </div>
    </div>
</div>

<!-- 个人资料模态框 -->
<div class="modal fade" id="profileModal" tabindex="-1" aria-labelledby="profileModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="border-radius: 12px;">
            <div class="modal-header" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 12px 12px 0 0;">
                <h5 class="modal-title" id="profileModalLabel">
                    <i class="bi bi-person-circle"></i> 个人资料
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding: 30px;">
                <c:if test="${not empty currentStudent}">
                    <div class="row mb-4">
                        <div class="col-12 text-center">
                            <div style="width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; color: white; font-size: 2rem;">
                                <i class="bi bi-person-circle"></i>
                            </div>
                            <h5 class="mb-1">
                                <c:choose>
                                    <c:when test="${not empty currentStudent.user.realName}">
                                        ${currentStudent.user.realName}
                                    </c:when>
                                    <c:otherwise>
                                        学生资料
                                    </c:otherwise>
                                </c:choose>
                            </h5>
                            <p class="text-muted mb-0">学生个人资料详情</p>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person me-2"></i>姓名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.realName}">
                                            ${currentStudent.user.realName}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-card-text me-2"></i>学号</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.studentNo}">
                                            ${currentStudent.studentNo}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person-badge me-2"></i>用户名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.username}">
                                            ${currentStudent.user.username}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-gender-ambiguous me-2"></i>性别</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${currentStudent.gender == 1}">
                                            <span class="badge" style="background: #e3f2fd; color: #1976d2;">男</span>
                                        </c:when>
                                        <c:when test="${currentStudent.gender == 0}">
                                            <span class="badge" style="background: #fce4ec; color: #e91e63;">女</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-building me-2"></i>班级</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.name}">
                                            ${currentStudent.clazz.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配班级</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-mortarboard me-2"></i>专业</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.name}">
                                            ${currentStudent.clazz.major.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配专业</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-bank me-2"></i>学院</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.college and not empty currentStudent.clazz.major.college.name}">
                                            ${currentStudent.clazz.major.college.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配学院</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-envelope me-2"></i>电子邮箱</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.email}">
                                            ${currentStudent.email}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-telephone me-2"></i>联系电话</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.phone}">
                                            ${currentStudent.phone}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>

                <c:if test="${empty currentStudent}">
                    <div class="text-center py-5">
                        <i class="bi bi-exclamation-circle text-warning" style="font-size: 3rem;"></i>
                        <h5 class="mt-3">无法获取学生资料</h5>
                        <p class="text-muted">请检查网络连接或联系管理员</p>
                    </div>
                </c:if>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                <a href="${pageContext.request.contextPath}/student/changePassword" class="btn" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                    <i class="bi bi-key me-1"></i>修改密码
                </a>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 用户名下拉菜单
    document.getElementById('userDropdownContainer').addEventListener('click', function(e) {
        e.stopPropagation();
        const dropdown = document.getElementById('userDropdown');
        dropdown.classList.toggle('show');
    });

    // 点击页面其他地方关闭下拉菜单
    document.addEventListener('click', function() {
        const dropdown = document.getElementById('userDropdown');
        dropdown.classList.remove('show');
    });

    // 侧边栏子菜单展开
    function toggleSubmenu(element) {
        const parent = element.parentElement;
        const submenu = parent.querySelector('.sidebar-submenu');

        // 关闭其他已展开的子菜单
        document.querySelectorAll('.sidebar-menu > li').forEach(li => {
            if (li !== parent) {
                li.classList.remove('open');
            }
        });

        // 展开当前子菜单
        parent.classList.toggle('open');
    }

    // 重置搜索
    function resetSearch() {
        window.location.href = '${pageContext.request.contextPath}/student/courses';
    }

    // 选课操作
    function selectCourse(courseId) {
        if (!confirm('确定要进行选课操作吗？')) {
            return;
        }

        fetch('${pageContext.request.contextPath}/student/courses/select', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: 'courseId=' + courseId
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert(data.message || '选课成功！');
                    location.reload();
                } else {
                    alert('选课失败：' + data.message);
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('发生错误，请稍后再试！');
            });
    }

    // 显示个人资料模态框
    function showProfileModal() {
        // 关闭用户名下拉菜单
        const dropdown = document.getElementById('userDropdown');
        dropdown.classList.remove('show');

        // 显示模态框
        try {
            if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
                const modal = new bootstrap.Modal(document.getElementById('profileModal'));
                modal.show();
            } else {
                // 备用方案：直接操作模态框
                const modal = document.getElementById('profileModal');
                if (modal) {
                    modal.classList.add('show');
                    modal.style.display = 'block';
                    document.body.classList.add('modal-open');
                }
            }
        } catch (error) {
            console.error('模态框显示失败:', error);
            alert('个人信息功能暂时不可用，请稍后再试');
        }
    }

    // 等待DOM完全加载后再执行
    document.addEventListener('DOMContentLoaded', function() {
        console.log('页面加载完成');
        
        // 检查Bootstrap是否正确加载
        if (typeof bootstrap === 'undefined') {
            console.error('Bootstrap未正确加载');
        } else {
            console.log('Bootstrap加载成功');
        }
    });
</script>
</body>
</html>

